/*
    main.c
    Achieve the AllBookBuilder
    BeginnerC
*/
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <unistd.h>
#include "./moudle/build_website/build_website.h"
#include "./moudle/build_single_book/build_single_book.h"
#include "./moudle/file/file.h"
#include "./moudle/config/config.h"
int main(int argc, char *argv[])
{
    Config *config = NULL;
    char *target_path = NULL;
    char *mdbook_path = NULL;
    char *temp = NULL;
    char *proc_path = NULL;
    char config_path[NAME_MAX] = {};
    if (2 != argc)
    {
        printf("Usage: AllBookBuilder [path]\n");
        return -1;
    }
    proc_path = GetProcPath();
    chdir(proc_path);
    free(proc_path);
    sprintf(config_path, "%s", ToAbsolutePath(DEFAULT_CONFIG_NAME));
    config = LoadConfig(config_path);
    mdbook_path = GetConfigValue(config, MDBOOK_PATH);
    temp = ToAbsolutePath(mdbook_path);
    sprintf(mdbook_path, "%s", temp);
    free(temp);
    target_path = ToAbsolutePath(argv[1]);
    BuildWebsite(target_path, config);
    free(target_path);
    FreeConfig(config);
    return 0;
}